<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <title>JSDoc: Source: Graphic.js</title>

    <script src="scripts/prettify/prettify.js"> </script>
    <script src="scripts/prettify/lang-css.js"> </script>
    <!--[if lt IE 9]>
      <script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script>
    <![endif]-->
    <link type="text/css" rel="stylesheet" href="styles/prettify-tomorrow.css">
    <link type="text/css" rel="stylesheet" href="styles/jsdoc-default.css">
</head>

<body>

<div id="main">

    <h1 class="page-title">Source: Graphic.js</h1>

    



    
    <section>
        <article>
            <pre class="prettyprint source linenums"><code>/**
 * @content 图形对象功能组件
 * @author fjl 2019-6-17 下午2:52:36
 */
import { NativeModules } from 'react-native';
import Dot from './Dot.js';
import Rect from './Rect.js';
import Map from './Map.js';
import { SketchEditor } from '@mapgis/mobile-react-native';

let G = NativeModules.JSGraphic;
/**
 * @class Graphic
 */
export default class Graphic {
  /**
   * 构造一个新的 Graphic 对象。
   * @memberOf Graphic
   * @returns {Promise.&lt;Graphic>}
   */
  async createObj() {
    try {
      let { GraphicId } = await G.createObj();
      let graphic = new Graphic();
      graphic._MGGraphicId = GraphicId;
      return graphic;
    } catch (e) {
      console.error(e);
    }
  }

  /**
   * 获取覆盖物的可见状态
   * @memberOf Graphic
   * @returns {Number} 返回层的状态 0 不可见 1 可见
   */
  async getState() {
    try {
      if(this.isValid()){
        let state = await G.getState(this._MGGraphicId);

        return state;
      } else {
        console.log('Graphic is invalid !');
      }
      
    } catch (e) {
      console.error(e);
    }
  }

  /**
   * 设置覆盖物的可见状态
   * @memberOf Graphic
   * @param {Number} state 覆盖物的可见状态。0 不可见；1 可见
   * @returns {Promise&lt;Void>}
   */
  async setState(state) {
    try {
      if(this.isValid()){
        await G.setState(this._MGGraphicId, state);
      } else {
        console.log('Graphic is invalid !');
      }
    } catch (e) {
      console.error(e);
    }
  }

  /**
   * 设置图形颜色
   * @memberOf Graphic
   * @param {String} color 图形颜色 eg:'rgba(128, 128, 128, 255)'
   * @returns {Promise&lt;Void>}
   */
  async setColor(color) {
    try {
      if(this.isValid()){
        await G.setColor(this._MGGraphicId, color);
      } else {
        console.log('Graphic is invalid !');
      }
    } catch (e) {
      console.error(e);
    }
  }

  /**
   * 获取图形的颜色
   * @memberOf Graphic
   * @returns {Promise&lt;String>} 图形颜色 eg:'rgba(128, 128, 128, 255)'
   */
  async getColor() {
    try {
      if(this.isValid()){
        let { color } = await G.getColor(this._MGGraphicId);
        return color;
      } else {
        console.log('Graphic is invalid !');
      }
     
    } catch (e) {
      console.error(e);
    }
  }

  /**
   * 获取图形中心点坐标
   * @memberOf Graphic
   * @returns {Promise&lt;Dot>}
   */
  async getCenterPoint() {
    try {
      if(this.isValid()){
        let { point2DId, x, y } = await G.getCenterPoint(this._MGGraphicId);
        let dot = new Dot();
        dot._MGDotId = point2DId;
        dot.x = x;
        dot.y = y;
        return dot;
      } else {
        console.log('Graphic is invalid !');
      }
      
    } catch (e) {
      console.error(e);
    }
  }

  /**
   * 获取图形外包矩形
   * @memberOf Graphic
   * @returns {Promise&lt;Rect>}
   */
  async getBoundingRect() {
    try {
      if(this.isValid()){
        let { RectId } = await G.getBoundingRect(this._MGGraphicId);
        let rect = new Rect();
        rect._MGRectId = RectId;
        
        return rect;
      } else {
        console.log('Graphic is invalid !');
      }
    } catch (e) {
      console.error(e);
    }
  }

  /**
   * 获取图形类型
   * @memberOf Graphic
   * @returns {Promise&lt;Number>} 图形类型。例：1---GraphicType.PointType
   */
  async getGraphicType() {
    try {
      if(this.isValid()){
        let GraphicType = await G.getGraphicType(this._MGGraphicId);

        return GraphicType;
      } else {
        console.log('Graphic is invalid !');
      }
    } catch (e) {
      console.error(e);
    }
  }

  /**
   * 设置点是否为像素单位(默认情况下为地图单位)
   * @memberOf Graphic
   * @param {boolean} pixel 点是否为像素单位
   * @returns {Promise&lt;void>}
   */
  async setPointByPixel(pixel) {
    try {
      if(this.isValid()){
        
        await G.setPointByPixel(this._MGGraphicId, pixel);

      } else {
        console.log('Graphic is invalid !');
      }
    } catch (e) {
      console.error(e);
    }
  }

  /**
   * 获取点是否为像素单位
   * @memberOf Graphic
   * @returns {Promise&lt;boolean>}
   */
  async isPointByPixel() {
    try {
      if(this.isValid()){
        let isPointByPixel = await G.isPointByPixel(this._MGGraphicId);

        return isPointByPixel;
      } else {
        console.log('Graphic is invalid !');
      }
    } catch (e) {
      console.error(e);
    }
  }

  /**
   * 设置图形的属性
   * @memberOf Graphic
   * @param {String} name 属性名称
   * @param {String} value 属性值
   * @returns {Promise&lt;void>}
   */
  async setAttributeValue(name, value) {
    try {
      if(this.isValid()){
        await G.setAttributeValue(this._MGGraphicId, name, value);

      } else {
        console.log('Graphic is invalid !');
      }
    } catch (e) {
      console.error(e);
    }
  }

  /**
   * 获取图形属性的数目
   * @memberOf Graphic
   * @returns {Promise&lt;Number>}
   */
  async getAttributeNum() {
    try {
      if(this.isValid()){
        let attributeNum = await G.getAttributeNum(this._MGGraphicId);

        return attributeNum;
      } else {
        console.log('Graphic is invalid !');
      }
    } catch (e) {
      console.error(e);
    }
  }

  /**
   * 根据索引获取图形属性名
   * @memberOf Graphic
   * @param {Number} index 索引
   * @returns {Promise&lt;String>}
   */
  async getAttributeName(index) {
    try {
      if(this.isValid()){
        let attributeName = await G.getAttributeName(this._MGGraphicId, index);
        
        return attributeName;
      } else {
        console.log('Graphic is invalid !');
      }
    } catch (e) {
      console.error(e);
    }
  }

  /**
   * 根据索引获取图形属性值
   * @memberOf Graphic
   * @param {Number} index 图形属性的索引，从0开始到属性数目减1
   * @returns {Promise&lt;String>}
   */
  async getAttributeValueByIndex(index) {
    try {
      if(this.isValid()){
        let attributeValue = await G.getAttributeValue(this._MGGraphicId, index);

        return attributeValue;
      } else {
        console.log('Graphic is invalid !');
      }
    } catch (e) {
      console.error(e);
    }
  }

  /**
   * 根据属性名称获取图形属性值
   * @memberOf Graphic
   * @param {String} name 属性名称
   * @returns {Promise&lt;String>}
   */
  async getAttributeValueByName(name) {
    try {
      if(this.isValid()){
        let attributeValue = await G.getAttributeValueByName(this._MGGraphicId, name);
        return attributeValue;
      } else {
        console.log('Graphic is invalid !');
      }
    } catch (e) {
      console.error(e);
    }
  }

  /**
   * 移除指定名称的属性
   * @memberOf Graphic
   * @param {String} name 属性名称
   * @returns {Promise&lt;void>}
   */
  async removeAttribute(name) {
    try {
      if(this.isValid()){
        await G.removeAttribute(this._MGGraphicId, name);
      } else {
        console.log('Graphic is invalid !');
      }
    } catch (e) {
      console.error(e);
    }
  }

  /**
   * 移除所有属性.
   * @memberOf Graphic
   * @returns {Promise&lt;void>}
   */
  async removeAllAttributes() {
    try {
      if(this.isValid()){
        await G.removeAllAttributes(this._MGGraphicId);
      } else {
        console.log('Graphic is invalid !');
      }
    } catch (e) {
      console.error(e);
    }
  }

  /**
   * 将几何对象转换为图形对象.
   * 常用于将查询出的要素转换为图形，在地图上做高亮显示.一个几何对象可能会转换出一个或多个图形对象
   * @static
   * @param {Geoemtry} geometry  待转换的几何对象
   * @returns {Promise&lt;Graphics>} 转换出的图形列表
   */
  static async toGraphicsFromGeometry(geometry)
  {
    try {
      let { GraphicArr } = await G.toGraphicsFromGeometry(geometry._MGGeometryId);
      let objArr = Map.getGraphics(GraphicArr);
      return objArr;
    } catch (e) {
      console.error(e);
    }
  }

  /**
   * 将图形对象转换为几何对象
   * @static
   * @param {Graphic} graphic 
   * @returns {Promise&lt;Geometry>}
   */
  static async toGeometry(graphic)
  {
    try {
      let { GeometryId, GeometryType, GeometryAnnoType } = await G.toGeometry(graphic._MGGraphicId);
      let geometry = SketchEditor.getGeometryByType(GeometryId, GeometryType, GeometryAnnoType);
      return geometry;
    } catch (e) {
      console.error(e);
    }
  }

  /**
   * 将一组同类型的图形对象转换为多几何对象(GeoPolygons、GeoPoints、GeoLines)
   * @statics
   * @param {Graphics} graphicArray 
   * @returns {Promise&lt;Geometry>}
   */
  static async toGeometrys(graphicArray)
  {
    try {
      let { GeometryId, GeometryType, GeometryAnnoType } = await G.toGeometrys(graphicArray);
      let geometry = SketchEditor.getGeometryByType(GeometryId, GeometryType, GeometryAnnoType);
      return geometry;
    } catch (e) {
      console.error(e);
    }
  }

  /**
   * 判断Graphic对象是否有效
   * 
   * @memberOf Graphic
   * @returns {boolean} 是否有效。true: 有效；false：无效
   */
  isValid(){
    try {
      if(this._MGGraphicId === undefined || this._MGGraphicId === null){
        return false;
      }else{
        return true;
      }
    } catch (e) {
      console.error(e);
    }
  }
}
</code></pre>
        </article>
    </section>




</div>

<nav>
    <h2><a href="index.html">Home</a></h2><h3>Classes</h3><ul><li><a href="AnnClsInfo.html">AnnClsInfo</a></li><li><a href="AnnInfo.html">AnnInfo</a></li><li><a href="Annotation.html">Annotation</a></li><li><a href="AnnotationCls.html">AnnotationCls</a></li><li><a href="AnnotationsOverlay.html">AnnotationsOverlay</a></li><li><a href="AnnotationView.html">AnnotationView</a></li><li><a href="BasCls.html">BasCls</a></li><li><a href="ClassItemValue.html">ClassItemValue</a></li><li><a href="CoordinateConvert.html">CoordinateConvert</a></li><li><a href="CoordinateConvertParameter.html">CoordinateConvertParameter</a></li><li><a href="CrossData.html">CrossData</a></li><li><a href="DataBase.html">DataBase</a></li><li><a href="DataBaseSync.html">DataBaseSync</a></li><li><a href="Document.html">Document</a></li><li><a href="DocumentItem.html">DocumentItem</a></li><li><a href="Dot.html">Dot</a></li><li><a href="Dot3D.html">Dot3D</a></li><li><a href="Dots.html">Dots</a></li><li><a href="Dots3D.html">Dots3D</a></li><li><a href="DownloadDataBaseParmeters.html">DownloadDataBaseParmeters</a></li><li><a href="DownloadLayerOption.html">DownloadLayerOption</a></li><li><a href="ElpParam.html">ElpParam</a></li><li><a href="ElpTransformation.html">ElpTransformation</a></li><li><a href="ElpTransParam.html">ElpTransParam</a></li><li><a href="Environment.html">Environment</a></li><li><a href="ExtField.html">ExtField</a></li><li><a href="FClsInfo.html">FClsInfo</a></li><li><a href="Feature.html">Feature</a></li><li><a href="FeatureEdit.html">FeatureEdit</a></li><li><a href="FeaturePagedResult.html">FeaturePagedResult</a></li><li><a href="FeatureQuery.html">FeatureQuery</a></li><li><a href="FeatureSync.html">FeatureSync</a></li><li><a href="Field.html">Field</a></li><li><a href="Fields.html">Fields</a></li><li><a href="FillStyle.html">FillStyle</a></li><li><a href="GeneralVectorLabel.html">GeneralVectorLabel</a></li><li><a href="GeoAnno.html">GeoAnno</a></li><li><a href="GeoLine.html">GeoLine</a></li><li><a href="GeoLines.html">GeoLines</a></li><li><a href="Geometry.html">Geometry</a></li><li><a href="GeometryExp.html">GeometryExp</a></li><li><a href="GeometryParams.html">GeometryParams</a></li><li><a href="GeomInfo.html">GeomInfo</a></li><li><a href="GeoPoints.html">GeoPoints</a></li><li><a href="GeoPolygon.html">GeoPolygon</a></li><li><a href="GeoPolygons.html">GeoPolygons</a></li><li><a href="GeoVarLine.html">GeoVarLine</a></li><li><a href="Graphic.html">Graphic</a></li><li><a href="GraphicCircle.html">GraphicCircle</a></li><li><a href="GraphicHeatmap.html">GraphicHeatmap</a></li><li><a href="GraphicImage.html">GraphicImage</a></li><li><a href="GraphicMultiPoint.html">GraphicMultiPoint</a></li><li><a href="GraphicPoint.html">GraphicPoint</a></li><li><a href="GraphicPolygon.html">GraphicPolygon</a></li><li><a href="GraphicPolylin.html">GraphicPolylin</a></li><li><a href="GraphicsOverlay.html">GraphicsOverlay</a></li><li><a href="GraphicsOverlays.html">GraphicsOverlays</a></li><li><a href="GraphicStippleLine.html">GraphicStippleLine</a></li><li><a href="GraphicText.html">GraphicText</a></li><li><a href="GroupLayer.html">GroupLayer</a></li><li><a href="HeatmapPoint.html">HeatmapPoint</a></li><li><a href="Image.html">Image</a></li><li><a href="IntUser.html">IntUser</a></li><li><a href="Label.html">Label</a></li><li><a href="LabelInfo.html">LabelInfo</a></li><li><a href="LatLng.html">LatLng</a></li><li><a href="LayerEnum.html">LayerEnum</a></li><li><a href="LinePlaceInfo.html">LinePlaceInfo</a></li><li><a href="LineStyle.html">LineStyle</a></li><li><a href="LinInfo.html">LinInfo</a></li><li><a href="MagnifierOption.html">MagnifierOption</a></li><li><a href="Map.html">Map</a></li><li><a href="MapLayer.html">MapLayer</a></li><li><a href="MapPosition.html">MapPosition</a></li><li><a href="Maps.html">Maps</a></li><li><a href="MapServer.html">MapServer</a></li><li><a href="MapServiceInfo.html">MapServiceInfo</a></li><li><a href="MapServiceLayerInfo.html">MapServiceLayerInfo</a></li><li><a href="MapView.html">MapView</a></li><li><a href="MeasureContentWillChangeListener.html">MeasureContentWillChangeListener</a></li><li><a href="MeasureOption.html">MeasureOption</a></li><li><a href="Model.html">Model</a></li><li><a href="ModelsOverlay.html">ModelsOverlay</a></li><li><a href="MultiClassTheme.html">MultiClassTheme</a></li><li><a href="MultiClassThemeInfo.html">MultiClassThemeInfo</a></li><li><a href="OGCWMTSMapServer.html">OGCWMTSMapServer</a></li><li><a href="PntInfo.html">PntInfo</a></li><li><a href="PointF.html">PointF</a></li><li><a href="PointPlaceInfo.html">PointPlaceInfo</a></li><li><a href="PointStyle.html">PointStyle</a></li><li><a href="QueryBound.html">QueryBound</a></li><li><a href="QueryDef.html">QueryDef</a></li><li><a href="RangeTheme.html">RangeTheme</a></li><li><a href="RangeThemeInfo.html">RangeThemeInfo</a></li><li><a href="Record.html">Record</a></li><li><a href="RecordSet.html">RecordSet</a></li><li><a href="Rect.html">Rect</a></li><li><a href="RegInfo.html">RegInfo</a></li><li><a href="RegionPlaceInfo.html">RegionPlaceInfo</a></li><li><a href="ServerLayer.html">ServerLayer</a></li><li><a href="SFeatureCls.html">SFeatureCls</a></li><li><a href="SimpleLabel.html">SimpleLabel</a></li><li><a href="SimpleModelLayer.html">SimpleModelLayer</a></li><li><a href="SimpleModelLayerUtil.html">SimpleModelLayerUtil</a></li><li><a href="SimpleTheme.html">SimpleTheme</a></li><li><a href="SketchEditor.html">SketchEditor</a></li><li><a href="SketchStyle.html">SketchStyle</a></li><li><a href="SnappingOption.html">SnappingOption</a></li><li><a href="SpaAnalysis.html">SpaAnalysis</a></li><li><a href="SpaCalculator.html">SpaCalculator</a></li><li><a href="SpaProjection.html">SpaProjection</a></li><li><a href="SpaRelation.html">SpaRelation</a></li><li><a href="SRefData.html">SRefData</a></li><li><a href="SyncBase.html">SyncBase</a></li><li><a href="SyncDataBaseParmeters.html">SyncDataBaseParmeters</a></li><li><a href="SyncLayerOption.html">SyncLayerOption</a></li><li><a href="TextAnnInfo.html">TextAnnInfo</a></li><li><a href="TextAnno.html">TextAnno</a></li><li><a href="TextStyle.html">TextStyle</a></li><li><a href="Theme.html">Theme</a></li><li><a href="ThemeInfo.html">ThemeInfo</a></li><li><a href="Themes.html">Themes</a></li><li><a href="TileMapServer.html">TileMapServer</a></li><li><a href="UniqueTheme.html">UniqueTheme</a></li><li><a href="UniqueThemeInfo.html">UniqueThemeInfo</a></li><li><a href="VectorCls.html">VectorCls</a></li><li><a href="VectorLabel.html">VectorLabel</a></li><li><a href="VectorLayer.html">VectorLayer</a></li><li><a href="VectorMapServer.html">VectorMapServer</a></li><li><a href="VectorTheme.html">VectorTheme</a></li><li><a href="VectorTileMapServer.html">VectorTileMapServer</a></li><li><a href="VisualMap.html">VisualMap</a></li><li><a href="XClsInfo.html">XClsInfo</a></li></ul><h3>Global</h3><ul><li><a href="global.html#addAnnotation">addAnnotation</a></li><li><a href="global.html#addAnnotations">addAnnotations</a></li><li><a href="global.html#animatePosition">animatePosition</a></li><li><a href="global.html#distanceOfGeometry">distanceOfGeometry</a></li><li><a href="global.html#getAllAnnotations">getAllAnnotations</a></li><li><a href="global.html#getAnnotation">getAnnotation</a></li><li><a href="global.html#getAnnotationCount">getAnnotationCount</a></li><li><a href="global.html#getGeometryByType">getGeometryByType</a></li><li><a href="global.html#indexOf">indexOf</a></li><li><a href="global.html#initialize">initialize</a></li><li><a href="global.html#moveAnnotation">moveAnnotation</a></li><li><a href="global.html#removeAllAnnotations">removeAllAnnotations</a></li><li><a href="global.html#removeAnnotation">removeAnnotation</a></li><li><a href="global.html#removeAnnotationByIndex">removeAnnotationByIndex</a></li><li><a href="global.html#removeAnnotations">removeAnnotations</a></li><li><a href="global.html#requestAuthorization">requestAuthorization</a></li><li><a href="global.html#setResolution">setResolution</a></li><li><a href="global.html#setScale">setScale</a></li><li><a href="global.html#setSize">setSize</a></li><li><a href="global.html#setSystemLibraryPath">setSystemLibraryPath</a></li><li><a href="global.html#toGeometry">toGeometry</a></li><li><a href="global.html#toGeometrys">toGeometrys</a></li><li><a href="global.html#toGraphicsFromGeometry">toGraphicsFromGeometry</a></li><li><a href="global.html#updatePositionbyViewPoint">updatePositionbyViewPoint</a></li></ul>
</nav>

<br class="clear">

<footer>
    Documentation generated by <a href="https://github.com/jsdoc/jsdoc">JSDoc 3.6.3</a> on Fri Jan 17 2020 16:23:46 GMT+0800 (GMT+08:00)
</footer>

<script> prettyPrint(); </script>
<script src="scripts/linenumber.js"> </script>
</body>
</html>
